home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / DocumentEvent.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  156 lines

  1. /*
  2.  * @(#)DocumentEvent.java    1.13 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.event;
  21.  
  22. import com.sun.java.swing.undo.*;
  23. import com.sun.java.swing.text.*;
  24.  
  25. /**
  26.  * Interface for document change notifications.
  27.  *
  28.  * @author  Timothy Prinzing
  29.  * @version 1.13 04/09/98
  30.  */
  31. public interface DocumentEvent {
  32.  
  33.     /**
  34.      * Returns the offset within the document of the start
  35.      * of the change.
  36.      *
  37.      * @return the offset >= 0
  38.      */
  39.     public int getOffset();
  40.  
  41.     /**
  42.      * Returns the length of the change.
  43.      *
  44.      * @return the length >= 0
  45.      */
  46.     public int getLength();
  47.  
  48.     /**
  49.      * Gets the document that sourced the change event.
  50.      *
  51.      * @returns the document
  52.      */
  53.     public Document getDocument();
  54.  
  55.     /**
  56.      * Gets the type of event.
  57.      *
  58.      * @return the type
  59.      */
  60.     public EventType getType();
  61.  
  62.     /**
  63.      * Gets the change information for the given element. 
  64.      * The change information describes what elements were
  65.      * added and removed and the location.  If there were
  66.      * no changes, null is returned.
  67.      *
  68.      * @param elem the element
  69.      * @return the change information, or null if the 
  70.      *   element was not modified
  71.      */
  72.     public ElementChange getChange(Element elem);
  73.  
  74.     /**
  75.      * Typesafe enumeration for document event types
  76.      */
  77.     public static final class EventType {
  78.  
  79.         private EventType(String s) {
  80.         typeString = s;
  81.     }
  82.  
  83.         /**
  84.          * Insert type.
  85.          */
  86.     public static final EventType INSERT = new EventType("INSERT");
  87.  
  88.         /**
  89.          * Remove type.
  90.          */
  91.     public static final EventType REMOVE = new EventType("REMOVE");
  92.  
  93.         /**
  94.          * Change type.
  95.          */
  96.     public static final EventType CHANGE = new EventType("CHANGE");
  97.  
  98.         /**
  99.          * Converts the type to a string.
  100.          *
  101.          * @return the string
  102.          */
  103.         public String toString() {
  104.         return typeString;
  105.     }
  106.  
  107.     private String typeString;
  108.     }
  109.  
  110.     /**
  111.      * Describes changes made to an element.
  112.      */
  113.     public interface ElementChange {
  114.  
  115.     /**
  116.      * Returns the element represented.  This is the element
  117.      * that was changed.
  118.          *
  119.          * @return the element
  120.      */
  121.     public Element getElement();
  122.  
  123.     /**
  124.      * Fetches the index within the element represented.
  125.      * This is the location that children were added
  126.      * and/or removed.
  127.          *
  128.          * @return the index >= 0
  129.      */
  130.     public int getIndex();
  131.  
  132.     /**
  133.      * Gets the child elements that were removed from the
  134.      * given parent element.  The parent element is expected
  135.      * to be one of the elements listed in the elementsModified
  136.      * method.  The element array returned is sorted in the
  137.      * order that the elements used to lie in the document.
  138.      *
  139.      * @return the child elements
  140.      */
  141.         public Element[] getChildrenRemoved();
  142.  
  143.     /**
  144.      * Gets the child elements that were added to the given
  145.      * parent element.  The parent element is expected to be
  146.      * one of the elements given in the elementsModified method.
  147.      * The element array returned is sorted in the order that
  148.      * the elements lie in the document.
  149.      *
  150.      * @return the child elements
  151.      */
  152.         public Element[] getChildrenAdded();
  153.  
  154.     }
  155. }
  156.